package com.example.work.controller;

import com.example.work.entity.DbCheckScoringMethodType;
import com.example.work.service.IScoringMethodTypeService;
import com.example.work.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: javaLiuwb
 * @date: 2024-11-25 19:30
 * @description:
 */
@RestController
@RequestMapping("/ScoreMethodType")
public class ScoreMethodTypeController {

    @Autowired
    private IScoringMethodTypeService scoringMethodTypeService;

    @RequestMapping("/list")
    public R list( ){
        List<DbCheckScoringMethodType> scoringMethodTypeList = scoringMethodTypeService.list();
        Map<String,Object> map=new HashMap<>();
        map.put("scoringMethodTypeList",scoringMethodTypeList);
        return R.ok(map);
    }

    //添加
    @RequestMapping("/save")
    public R save(@RequestBody DbCheckScoringMethodType dbCheckScoringMethodType){
        //System.out.println(dbCheckCategory.toString());

        if(dbCheckScoringMethodType.getId()==null){
            Date date = new Date();
            dbCheckScoringMethodType.setCreateTime(date);
            dbCheckScoringMethodType.setUpdateTime(date);
            scoringMethodTypeService.save(dbCheckScoringMethodType);
        }else {
            Date date = new Date();
            dbCheckScoringMethodType.setUpdateTime(date);
            scoringMethodTypeService.saveOrUpdate(dbCheckScoringMethodType);
        }
        return R.ok();
    }

    //删除
    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable(value = "id") String id){

        scoringMethodTypeService.removeById(id);
        return R.ok();
    }

}
